using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Facebook.Components;
using Facebook.Types;

namespace Facebook.Forms
{
    public partial class FacebookExtendedPermission : Form
    {
        public FacebookExtendedPermission()
        {
            InitializeComponent();
        }

		private FacebookService _facebookService;
		Enums.Extended_Permissions _permission;

		internal FacebookExtendedPermission(string loginUrl, Enums.Extended_Permissions permission, FacebookService service)
			: this(new Uri(loginUrl), permission, service)
		{
		}

		internal FacebookExtendedPermission(Uri loginUrl, Enums.Extended_Permissions permission, FacebookService service)
			: this()
		{
			_facebookService = service;
			_permission = permission;
			wbFacebookLogin.Navigate(loginUrl);
		}


        private void wbFacebookLogin_Navigated(object sender, WebBrowserNavigatedEventArgs e)
        {
			if (e.Url.PathAndQuery.IndexOf("authorize.php") > -1 && e.Url.Fragment == "#")
			{
				DialogResult = (_facebookService.HasPermission(_permission)) ? DialogResult.OK : DialogResult.Cancel;
			}
        }

        private void FacebookAuthentication_Closed(object sender, EventArgs e)
        {
            if (DialogResult != DialogResult.OK)
            {
                DialogResult = DialogResult.Cancel;
            }
        }
    }
}